home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / modes / texinfo.el.z / texinfo.el
Encoding:
Text File  |  1998-05-21  |  30.4 KB  |  807 lines

  1. ;;; texinfo.el --- major mode for editing Texinfo files
  2.  
  3. ;; Copyright (C) 1985, '88, '89, 
  4. ;;                '90, '91, '92, '93 Free Software Foundation, Inc.
  5.  
  6. ;; Author: Robert J. Chassell          
  7. ;; Maintainer: FSF
  8. ;; Keywords: tex wp
  9.  
  10. ;; This file is part of XEmacs.
  11.  
  12. ;; XEmacs is free software; you can redistribute it and/or modify it
  13. ;; under the terms of the GNU General Public License as published by
  14. ;; the Free Software Foundation; either version 2, or (at your option)
  15. ;; any later version.
  16.  
  17. ;; XEmacs is distributed in the hope that it will be useful, but
  18. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20. ;; General Public License for more details.
  21.  
  22. ;; You should have received a copy of the GNU General Public License
  23. ;; along with XEmacs; see the file COPYING.  If not, write to the 
  24. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  25. ;; Boston, MA 02111-1307, USA.
  26.  
  27. ;;; Synched up with: FSF 19.30.
  28.  
  29. (defgroup texinfo nil
  30.   "Major mode for editing Texinfo files."
  31.   :group 'docs
  32.   :group 'tex
  33.   :group 'wp)
  34.  
  35.  
  36. ;;; Autoloads:
  37.  
  38. (autoload 'makeinfo-region
  39.           "makeinfo"
  40.   "Make Info file from region of current Texinfo file, and switch to it.
  41.  
  42. This command does not offer the `next-error' feature since it would
  43. apply to a temporary file, not the original; use the `makeinfo-buffer'
  44. command to gain use of `next-error'."
  45.           t nil)
  46.  
  47. (autoload 'makeinfo-buffer
  48.           "makeinfo"
  49.   "Make Info file from current buffer.
  50.  
  51. Use the \\[next-error] command to move to the next error 
  52. \(if there are errors\)."
  53.           t nil)
  54.  
  55. (autoload 'kill-compilation
  56.           "compile"
  57.   "Kill the process made by the \\[compile] command."
  58.           t nil)
  59.  
  60. (autoload 'makeinfo-recenter-compilation-buffer
  61.           "makeinfo"
  62.   "Redisplay `*compilation*' buffer so most recent output can be seen.
  63. The last line of the buffer is displayed on
  64. line LINE of the window, or centered if LINE is nil."
  65.           t nil)
  66.  
  67. (autoload 'texinfo-make-menu
  68.           "texnfo-upd"
  69.   "Without any prefix argument, make or update a menu.
  70. Make the menu for the section enclosing the node found following point.
  71.  
  72. Non-nil argument (prefix, if interactive) means make or update menus
  73. for nodes within or part of the marked region.
  74.  
  75. Whenever a menu exists, and is being updated, the descriptions that
  76. are associated with node names in the pre-existing menu are
  77. incorporated into the new menu.  Otherwise, the nodes' section titles
  78. are inserted as descriptions."
  79.           t nil)
  80.  
  81. (autoload 'texinfo-all-menus-update
  82.           "texnfo-upd"
  83.   "Update every regular menu in a Texinfo file.
  84. Remove pre-existing master menu, if there is one.
  85.  
  86. If called with a non-nil argument, this function first updates all the
  87. nodes in the buffer before updating the menus."
  88.           t nil)
  89.  
  90. (autoload 'texinfo-master-menu
  91.           "texnfo-upd"
  92.   "Make a master menu for a whole Texinfo file.
  93. Non-nil argument (prefix, if interactive) means first update all
  94. existing nodes and menus.  Remove pre-existing master menu, if there is one.
  95.  
  96. This function creates a master menu that follows the top node.  The
  97. master menu includes every entry from all the other menus.  It
  98. replaces any existing ordinary menu that follows the top node.
  99.  
  100. If called with a non-nil argument, this function first updates all the
  101. menus in the buffer (incorporating descriptions from pre-existing
  102. menus) before it constructs the master menu.
  103.  
  104. The function removes the detailed part of an already existing master
  105. menu.  This action depends on the pre-exisitng master menu using the
  106. standard `texinfo-master-menu-header'.
  107.  
  108. The master menu has the following format, which is adapted from the
  109. recommendation in the Texinfo Manual:
  110.  
  111.    * The first part contains the major nodes in the Texinfo file: the
  112.      nodes for the chapters, chapter-like sections, and the major
  113.      appendices.  This includes the indices, so long as they are in
  114.      chapter-like sections, such as unnumbered sections.
  115.  
  116.    * The second and subsequent parts contain a listing of the other,
  117.      lower level menus, in order.  This way, an inquirer can go
  118.      directly to a particular node if he or she is searching for
  119.      specific information.
  120.  
  121. Each of the menus in the detailed node listing is introduced by the
  122. title of the section containing the menu."
  123.           t nil)
  124.  
  125. (autoload 'texinfo-indent-menu-description
  126.           "texnfo-upd"
  127.   "Indent every description in menu following point to COLUMN.  
  128. Non-nil argument (prefix, if interactive) means indent every
  129. description in every menu in the region.  Does not indent second and
  130. subsequent lines of a multi-line description."
  131.           t nil)
  132.  
  133. (autoload 'texinfo-insert-node-lines
  134.           "texnfo-upd"
  135.   "Insert missing `@node' lines in region of Texinfo file.
  136. Non-nil argument (prefix, if interactive) means also to insert the
  137. section titles as node names; and also to insert the section titles as
  138. node names in pre-existing @node lines that lack names."
  139.           t nil)
  140.  
  141. (autoload 'texinfo-start-menu-description
  142.           "texnfo-upd"
  143.   "In this menu entry, insert the node's section title as a description. 
  144. Position point at beginning of description ready for editing.
  145. Do not insert a title if the line contains an existing description.
  146.  
  147. You will need to edit the inserted text since a useful description
  148. complements the node name rather than repeats it as a title does."
  149.           t nil)
  150.  
  151. (autoload 'texinfo-multiple-files-update
  152.           "texnfo-upd"
  153.   "Update first node pointers in each file included in OUTER-FILE;
  154. create or update main menu in the outer file that refers to such nodes. 
  155. This does not create or update menus or pointers within the included files.
  156.  
  157. With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
  158. insert a master menu in OUTER-FILE.  This does not create or update
  159. menus or pointers within the included files.
  160.  
  161. With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
  162. interactive), update all the menus and all the `Next', `Previous', and
  163. `Up' pointers of all the files included in OUTER-FILE before inserting
  164. a master menu in OUTER-FILE.
  165.  
  166. The command also updates the `Top' level node pointers of OUTER-FILE.
  167.  
  168. Notes: 
  169.  
  170.   * this command does NOT save any files--you must save the
  171.     outer file and any modified, included files.
  172.  
  173.   * except for the `Top' node, this command does NOT handle any
  174.     pre-existing nodes in the outer file; hence, indices must be
  175.     enclosed in an included file.
  176.  
  177. Requirements:
  178.  
  179.   * each of the included files must contain exactly one highest
  180.     hierarchical level node, 
  181.   * this highest node must be the first node in the included file,
  182.   * each highest hierarchical level node must be of the same type.
  183.  
  184. Thus, normally, each included file contains one, and only one,
  185. chapter."
  186.           t nil)
  187.  
  188.  
  189. ;;; Code:
  190.  
  191. ;;; Don't you dare insert any `require' calls at top level in this file--rms.
  192.  
  193. ;;; Syntax table
  194.  
  195. (defvar texinfo-mode-syntax-table nil)
  196.  
  197. (if texinfo-mode-syntax-table
  198.     nil
  199.   (setq texinfo-mode-syntax-table (make-syntax-table))
  200.   (modify-syntax-entry ?\" " " texinfo-mode-syntax-table)
  201.   (modify-syntax-entry ?\\ " " texinfo-mode-syntax-table)
  202.   (modify-syntax-entry ?@ "\\" texinfo-mode-syntax-table)
  203.   (modify-syntax-entry ?\^q "\\" texinfo-mode-syntax-table)
  204.   (modify-syntax-entry ?\[ "(]" texinfo-mode-syntax-table)
  205.   (modify-syntax-entry ?\] ")[" texinfo-mode-syntax-table)
  206.   (modify-syntax-entry ?{ "(}" texinfo-mode-syntax-table)
  207.   (modify-syntax-entry ?} "){" texinfo-mode-syntax-table)
  208.   (modify-syntax-entry ?\' "w" texinfo-mode-syntax-table))
  209.  
  210. ;; Written by Wolfgang Bangerth <zcg51122@rpool1.rus.uni-stuttgart.de>
  211. ;; To overide this example, set either `imenu-generic-expression'
  212. ;; or `imenu-create-index-function'.
  213. ;(defvar texinfo-imenu-generic-expression
  214. ;  '((nil "^@node[ \t]+\\([^,\n]*\\)" 1)
  215. ;    ("Chapters" "^@chapter[ \t]+\\(.*\\)$" 1))
  216.  
  217. ;  "Imenu generic expression for TexInfo mode.  See `imenu-generic-expression'.")
  218.  
  219. (defvar texinfo-font-lock-keywords
  220.   (list
  221.    ;; All but the first 2 had an OVERRIDE of t.
  222.    ;; It didn't seem to be any better, and it's slower--simon.
  223.    '("^\\(@c\\|@comment\\)\\>.*" . font-lock-comment-face)     ;comments
  224.    ;; Robert J. Chassell <bob@gnu.ai.mit.edu> says remove this line.
  225.    ;'("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
  226.    "@\\(@\\|[^}\t \n{]+\\)"                    ;commands
  227.    '("^\\(*.*\\)[\t ]*$" 1 font-lock-function-name-face t)     ;menu items
  228.    '("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face)
  229.    '("@\\(file\\|kbd\\|key\\){\\([^}]+\\)" 2 font-lock-string-face)
  230.    '("@\\(samp\\|code\\|var\\|math\\){\\([^}]+\\)"
  231.      2 font-lock-variable-name-face)
  232.    '("@\\(cite\\|xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-reference-face)
  233.    '("@\\(end\\|item\\) *\\(.+\\)" 2 font-lock-function-name-face keep)
  234.    )
  235.   "Additional expressions to highlight in TeXinfo mode.")
  236.  
  237. ;; An older version.
  238. ;(defconst texinfo-font-lock-keywords (purecopy
  239. ;  (list
  240. ;   "@\\(@\\|[^}\t \n{]+\\)"                    ;commands
  241. ;   '("^\\(@c\\|@comment\\)[ \t].*$" 0 font-lock-comment-face t)    ;comments
  242. ;   '("^\\(*.*\\)[\t ]*$" 1 font-lock-function-name-face t)    ;menu items
  243. ;   '("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face t)
  244. ;   '("@\\(file\\|kbd\\|key\\){\\([^}]+\\)" 2 font-lock-string-face t)
  245. ;   '("@\\(samp\\|code\\|var\\){\\([^}]+\\)" 2 font-lock-function-name-face t)
  246. ;   '("@\\(xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-keyword-face t)
  247. ;   '("@end *\\([a-zA-Z0-9]+\\)[ \t]*$" 1 font-lock-function-name-face t)
  248. ;   '("@item \\(.*\\)$" 1 font-lock-function-name-face t)
  249. ;   '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
  250. ;   ))
  251. ;  "Additional expressions to highlight in TeXinfo mode.")
  252.  
  253. (put 'texinfo-mode 'font-lock-defaults '(texinfo-font-lock-keywords t))
  254.  
  255. ;;; Keybindings
  256. (defvar texinfo-mode-map nil)
  257.  
  258. ;;; Keys common both to Texinfo mode and to TeX shell.
  259.  
  260. (defun texinfo-define-common-keys (keymap)
  261.   "Define the keys both in Texinfo mode and in the texinfo-tex-shell."
  262.   (define-key keymap "\C-c\C-t\C-k"    'tex-kill-job)
  263.   (define-key keymap "\C-c\C-t\C-x"    'texinfo-quit-job)
  264.   (define-key keymap "\C-c\C-t\C-l"    'tex-recenter-output-buffer)
  265.   (define-key keymap "\C-c\C-t\C-d"    'texinfo-delete-from-print-queue)
  266.   (define-key keymap "\C-c\C-t\C-q"    'tex-show-print-queue)
  267.   (define-key keymap "\C-c\C-t\C-p"    'texinfo-tex-print)
  268.   (define-key keymap "\C-c\C-t\C-i"    'texinfo-texindex)
  269.  
  270.   (define-key keymap "\C-c\C-t\C-r"    'texinfo-tex-region)
  271.   (define-key keymap "\C-c\C-t\C-b"    'texinfo-tex-buffer))
  272.  
  273. ;; Mode documentation displays commands in reverse order 
  274. ;; from how they are listed in the texinfo-mode-map.
  275.  
  276. (if texinfo-mode-map
  277.     nil
  278.   (setq texinfo-mode-map (make-sparse-keymap))
  279.  
  280.   ;; bindings for `texnfo-tex.el'
  281.   (texinfo-define-common-keys texinfo-mode-map)
  282.  
  283.   ;; bindings for `makeinfo.el'
  284.   (define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation)
  285.   (define-key texinfo-mode-map "\C-c\C-m\C-l" 
  286.     'makeinfo-recenter-compilation-buffer)
  287.   (define-key texinfo-mode-map "\C-c\C-m\C-r" 'makeinfo-region)
  288.   (define-key texinfo-mode-map "\C-c\C-m\C-b" 'makeinfo-buffer)
  289.  
  290.   ; Bindings for texinfmt.el.
  291.   (define-key texinfo-mode-map "\C-c\C-e\C-r"    'texinfo-format-region)
  292.   (define-key texinfo-mode-map "\C-c\C-e\C-b"    'texinfo-format-buffer)
  293.  
  294.   ;; bindings for updating nodes and menus
  295.  
  296.   (define-key texinfo-mode-map "\C-c\C-um"   'texinfo-master-menu)
  297.  
  298.   (define-key texinfo-mode-map "\C-c\C-u\C-m"   'texinfo-make-menu)
  299.   (define-key texinfo-mode-map "\C-c\C-u\C-n"   'texinfo-update-node)
  300.   (define-key texinfo-mode-map "\C-c\C-u\C-e"   'texinfo-every-node-update)
  301.   (define-key texinfo-mode-map "\C-c\C-u\C-a"   'texinfo-all-menus-update)
  302.  
  303.   (define-key texinfo-mode-map "\C-c\C-s"     'texinfo-show-structure)
  304.  
  305.   (define-key texinfo-mode-map "\C-c}"        'up-list)
  306.   (define-key texinfo-mode-map "\C-c{"        'texinfo-insert-braces)
  307.  
  308.   ;; bindings for inserting strings
  309.  
  310.   (define-key texinfo-mode-map "\C-c\C-c\C-d" 'texinfo-start-menu-description)
  311.  
  312.   (define-key texinfo-mode-map "\C-c\C-cv"    'texinfo-insert-@var)
  313.   (define-key texinfo-mode-map "\C-c\C-ct"    'texinfo-insert-@table)
  314.   (define-key texinfo-mode-map "\C-c\C-cs"    'texinfo-insert-@samp)
  315.   (define-key texinfo-mode-map "\C-c\C-co"    'texinfo-insert-@noindent)
  316.   (define-key texinfo-mode-map "\C-c\C-cn"    'texinfo-insert-@node)
  317.   (define-key texinfo-mode-map "\C-c\C-ck"    'texinfo-insert-@kbd)
  318.   (define-key texinfo-mode-map "\C-c\C-ci"    'texinfo-insert-@item)
  319.   (define-key texinfo-mode-map "\C-c\C-cf"    'texinfo-insert-@file)
  320.   (define-key texinfo-mode-map "\C-c\C-cx"    'texinfo-insert-@example)
  321.   (define-key texinfo-mode-map "\C-c\C-ce"    'texinfo-insert-@end)
  322.   (define-key texinfo-mode-map "\C-c\C-cd"    'texinfo-insert-@dfn)
  323.   (define-key texinfo-mode-map "\C-c\C-cc"    'texinfo-insert-@code))
  324.  
  325.  
  326. ;;; Texinfo mode
  327.  
  328. (defvar texinfo-chapter-level-regexp 
  329.   "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
  330.   "Regular expression matching Texinfo chapter-level headings.
  331. This does not match `@node' and does not match the `@top' command.")
  332.  
  333. ;;;###autoload
  334. (defun texinfo-mode ()
  335.   "Major mode for editing Texinfo files.
  336.  
  337.   It has these extra commands:
  338. \\{texinfo-mode-map}
  339.  
  340.   These are files that are used as input for TeX to make printed manuals
  341. and also to be turned into Info files with \\[makeinfo-buffer] or
  342. the `makeinfo' program.  These files must be written in a very restricted and
  343. modified version of TeX input format.
  344.  
  345.   Editing commands are like text-mode except that the syntax table is
  346. set up so expression commands skip Texinfo bracket groups.  To see
  347. what the Info version of a region of the Texinfo file will look like,
  348. use \\[makeinfo-region], which runs `makeinfo' on the current region.
  349.  
  350.   You can show the structure of a Texinfo file with \\[texinfo-show-structure].
  351. This command shows the structure of a Texinfo file by listing the
  352. lines with the @-sign commands for @chapter, @section, and the like.
  353. These lines are displayed in another window called the *Occur* window.
  354. In that window, you can position the cursor over one of the lines and
  355. use \\[occur-mode-goto-occurrence], to jump to the corresponding spot
  356. in the Texinfo file.
  357.  
  358.   In addition, Texinfo mode provides commands that insert various
  359. frequently used @-sign commands into the buffer.  You can use these
  360. commands to save keystrokes.  And you can insert balanced braces with
  361. \\[texinfo-insert-braces] and later use the command \\[up-list] to
  362. move forward past the closing brace.
  363.  
  364. Also, Texinfo mode provides functions for automatically creating or
  365. updating menus and node pointers.  These functions
  366.  
  367.   * insert the `Next', `Previous' and `Up' pointers of a node,
  368.   * insert or update the menu for a section, and
  369.   * create a master menu for a Texinfo source file.
  370.  
  371. Here are the functions:
  372.  
  373.     texinfo-update-node                \\[texinfo-update-node]
  374.     texinfo-every-node-update          \\[texinfo-every-node-update]
  375.     texinfo-sequential-node-update 
  376.  
  377.     texinfo-make-menu                  \\[texinfo-make-menu]
  378.     texinfo-all-menus-update           \\[texinfo-all-menus-update]
  379.     texinfo-master-menu
  380.  
  381.     texinfo-indent-menu-description (column &optional region-p)
  382.  
  383. The `texinfo-column-for-description' variable specifies the column to
  384. which menu descriptions are indented. 
  385.  
  386. Passed an argument (a prefix argument, if interactive), the
  387. `texinfo-update-node' and `texinfo-make-menu' functions do their jobs
  388. in the region.
  389.  
  390. To use the updating commands, you must structure your Texinfo file
  391. hierarchically, such that each `@node' line, with the exception of the
  392. Top node, is accompanied by some kind of section line, such as an
  393. `@chapter' or `@section' line.
  394.  
  395. If the file has a `top' node, it must be called `top' or `Top' and
  396. be the first node in the file.
  397.  
  398. Entering Texinfo mode calls the value of text-mode-hook, and then the
  399. value of texinfo-mode-hook."
  400.   (interactive)
  401.   (text-mode)
  402.   (setq mode-name "Texinfo")
  403.   (setq major-mode 'texinfo-mode)
  404.   (use-local-map texinfo-mode-map)
  405.   (set-syntax-table texinfo-mode-syntax-table)
  406.   (make-local-variable 'page-delimiter)
  407.   (setq page-delimiter 
  408.         (concat 
  409.          "^@node [ \t]*[Tt]op\\|^@\\(" 
  410.          texinfo-chapter-level-regexp 
  411.          "\\)"))
  412.   (make-local-variable 'require-final-newline)
  413.   (setq require-final-newline t)
  414.   (make-local-variable 'indent-tabs-mode)
  415.   (setq indent-tabs-mode nil)
  416.   (make-local-variable 'paragraph-separate)
  417.   (setq paragraph-separate (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-separate))
  418.   (make-local-variable 'paragraph-start)
  419.   (setq paragraph-start (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-start))
  420.   (make-local-variable 'fill-column)
  421.   (setq fill-column 72)
  422.   (make-local-variable 'comment-start)
  423.   (setq comment-start "@c ")
  424.   (make-local-variable 'comment-start-skip)
  425.   (setq comment-start-skip "@c +")
  426.   (make-local-variable 'words-include-escapes)
  427.   (setq words-include-escapes t)
  428. ;  (make-local-variable 'imenu-generic-expression)
  429. ;  (setq imenu-generic-expression texinfo-imenu-generic-expression)
  430.   (make-local-variable 'tex-start-of-header)
  431.   (setq tex-start-of-header "%**start")
  432.   (make-local-variable 'tex-end-of-header)
  433.   (setq tex-end-of-header "%**end")
  434.   (run-hooks 'text-mode-hook 'texinfo-mode-hook))
  435.  
  436.  
  437. ;;; Insert string commands
  438.  
  439. (defconst texinfo-environment-regexp
  440.   "^[ \t]*@\\(f?table\\|enumerate\\|itemize\
  441. \\|ifhtml\\|ifinfo\\|iftex\\|ifset\\|ifclear\
  442. \\|example\\|quotation\\|lisp\\|smallexample\\|smalllisp\\|display\\|format\
  443. \\|flushleft\\|flushright\\|ignore\\|group\\|tex\\|html\\|cartouche\\|menu\
  444. \\|titlepage\\|end\\|def[a-z]*[a-wyz]\\>\\)"
  445.   "Regexp for environment-like Texinfo list commands.
  446. Subexpression 1 is what goes into the corresponding `@end' statement.")
  447.  
  448. (defun texinfo-insert-@end ()
  449.   "Insert the matching `@end' for the last Texinfo command that needs one."
  450.   (interactive)
  451.   (let ((depth 1) string)
  452.     (save-excursion
  453.       (while (and (> depth 0)
  454.           (re-search-backward texinfo-environment-regexp nil t)
  455.     (if (looking-at "@end")
  456.         (setq depth (1+ depth))
  457.       (setq depth (1- depth)))))
  458.       (looking-at texinfo-environment-regexp)
  459.       (if (zerop depth)
  460.       (setq string
  461.         (buffer-substring (match-beginning 1)
  462.                   (match-end 1)))))
  463.     (insert "@end ")
  464.     (if string (insert string "\n"))))
  465.  
  466. ;; The following insert commands accept a prefix arg N, which is the
  467. ;; number of words (actually s-exprs) that should be surrounded by
  468. ;; braces.  Thus you can first paste a variable name into a .texinfo
  469. ;; buffer, then say C-u 1 C-c C-c v at the beginning of the just
  470. ;; pasted variable name to put @var{...} *around* the variable name.
  471. ;; Operate on previous word or words with negative arg.
  472.  
  473. ;; These commands use texinfo-insert-@-with-arg
  474. (defun texinfo-insert-@-with-arg (string &optional arg)
  475.   (if arg 
  476.       (progn
  477.         (setq arg (prefix-numeric-value arg))
  478.         (if (< arg 0)
  479.             (progn
  480.               (skip-chars-backward " \t\n\r\f")
  481.               (save-excursion
  482.                 (forward-sexp arg)
  483.                 (insert "@" string "{"))
  484.               (insert "}"))
  485.           (skip-chars-forward " \t\n\r\f")
  486.           (insert "@" string "{")
  487.           (forward-sexp arg)
  488.           (insert "}")))
  489.     (insert "@" string "{}")
  490.     (backward-char)))
  491.  
  492. (defun texinfo-insert-braces ()
  493.   "Make a pair of braces and be poised to type inside of them.
  494. Use \\[up-list] to move forward out of the braces."
  495.   (interactive)
  496.   (insert "{}")
  497.   (backward-char))
  498.  
  499. (defun texinfo-insert-@code (&optional arg)
  500.   "Insert a `@code{...}' command in a Texinfo buffer.
  501. A numeric argument says how many words the braces should surround.
  502. The default is not to surround any existing words with the braces."
  503.   (interactive "P")
  504.   (texinfo-insert-@-with-arg "code" arg))
  505.  
  506. (defun texinfo-insert-@dfn (&optional arg)
  507.   "Insert a `@dfn{...}' command in a Texinfo buffer.
  508. A numeric argument says how many words the braces should surround.
  509. The default is not to surround any existing words with the braces."
  510.   (interactive "P")
  511.   (texinfo-insert-@-with-arg "dfn" arg))
  512.  
  513. (defun texinfo-insert-@example ()
  514.   "Insert the string `@example' in a Texinfo buffer."
  515.   (interactive)
  516.   (insert "@example\n"))
  517.  
  518. (defun texinfo-insert-@file (&optional arg)
  519.   "Insert a `@file{...}' command in a Texinfo buffer.
  520. A numeric argument says how many words the braces should surround.
  521. The default is not to surround any existing words with the braces."
  522.   (interactive "P")
  523.   (texinfo-insert-@-with-arg "file" arg))
  524.  
  525. (defun texinfo-insert-@item ()
  526.   "Insert the string `@item' in a Texinfo buffer."
  527.   (interactive)
  528.   (insert "@item")
  529.   (newline))
  530.  
  531. (defun texinfo-insert-@kbd (&optional arg)
  532.   "Insert a `@kbd{...}' command in a Texinfo buffer.
  533. A numeric argument says how many words the braces should surround.
  534. The default is not to surround any existing words with the braces."
  535.   (interactive "P")
  536.   (texinfo-insert-@-with-arg "kbd" arg))
  537.  
  538. (defun texinfo-insert-@node ()
  539.   "Insert the string `@node' in a Texinfo buffer.
  540. This also inserts on the following line a comment indicating
  541. the order of arguments to @node."
  542.   (interactive)
  543.   (insert "@node \n@comment  node-name,  next,  previous,  up")
  544.   (forward-line -1)
  545.   (forward-char 6))
  546.  
  547. (defun texinfo-insert-@noindent ()
  548.   "Insert the string `@noindent' in a Texinfo buffer."
  549.   (interactive)
  550.   (insert "@noindent\n"))
  551.  
  552. (defun texinfo-insert-@samp (&optional arg)
  553.   "Insert a `@samp{...}' command in a Texinfo buffer.
  554. A numeric argument says how many words the braces should surround.
  555. The default is not to surround any existing words with the braces."
  556.   (interactive "P")
  557.   (texinfo-insert-@-with-arg "samp" arg))
  558.  
  559. (defun texinfo-insert-@table (&optional arg)
  560.   "Insert the string `@table' in a Texinfo buffer."
  561.   (interactive "P")
  562.   (insert "@table "))
  563.  
  564. (defun texinfo-insert-@var (&optional arg)
  565.   "Insert a `@var{}' command in a Texinfo buffer.
  566. A numeric argument says how many words the braces should surround.
  567. The default is not to surround any existing words with the braces."
  568.   (interactive "P")
  569.   (texinfo-insert-@-with-arg "var" arg))
  570.  
  571. ;;; Texinfo file structure
  572.  
  573. (defun texinfo-show-structure (&optional nodes-too) 
  574.   "Show the structure of a Texinfo file.
  575. List the lines in the file that begin with the @-sign commands for
  576. @chapter, @section, and the like.
  577.  
  578. With optional argument (prefix if interactive), list both the lines
  579. with @-sign commands for @chapter, @section, and the like, and list
  580. @node lines.
  581.  
  582. Lines with structuring commands beginning in them are displayed in
  583. another buffer named `*Occur*'.  In that buffer, you can move point to
  584. one of those lines and then use \\<occur-mode-map>\\[occur-mode-goto-occurrence], 
  585. to jump to the corresponding spot in the Texinfo source file."
  586.  
  587.   (interactive "P")
  588.   (require 'texnfo-upd)
  589.   (save-excursion 
  590.     (goto-char (point-min))
  591.     (if nodes-too
  592.         (occur (concat "\\(^@node\\)\\|" texinfo-section-types-regexp))
  593.       (occur texinfo-section-types-regexp)))
  594.   (pop-to-buffer "*Occur*")
  595.   (goto-char (point-min))
  596.   (flush-lines "-----")
  597.   ;; Now format the "*Occur*" buffer to show the structure.
  598.   ;; Thanks to ceder@signum.se (Per Cederqvist)
  599.   (goto-char (point-max))
  600.   (let ((margin 5))
  601.     (while (re-search-backward "^ *[0-9]*:" nil 0)
  602.       (re-search-forward ":")
  603.       (setq margin
  604.             (cond
  605.              ((looking-at
  606.                (concat "@\\(" texinfo-chapter-level-regexp "\\)")) 5)
  607.              ;; ((looking-at "@chapter ") 5)
  608.              ;; ((looking-at "@unnumbered ") 5)
  609.              ;; ((looking-at "@appendix ") 5)
  610.              ;; ((looking-at "@majorheading ") 5)
  611.              ;; ((looking-at "@chapheading ") 5)
  612.  
  613.              ((looking-at
  614.                (concat "@\\(" texinfo-section-level-regexp "\\)")) 9)
  615.              ;; ((looking-at "@section ") 9)
  616.              ;; ((looking-at "@unnumberedsec ") 9)
  617.              ;; ((looking-at "@appendixsec ") 9)
  618.              ;; ((looking-at "@heading ") 9)
  619.  
  620.              ((looking-at 
  621.                (concat "@\\(" texinfo-subsection-level-regexp "\\)")) 13)
  622.              ;; ((looking-at "@subsection ") 13)
  623.              ;; ((looking-at "@unnumberedsubsec ") 13)
  624.              ;; ((looking-at "@appendixsubsec ") 13)
  625.              ;; ((looking-at "@subheading ") 13)
  626.  
  627.              ((looking-at 
  628.                (concat "@\\(" texinfo-subsubsection-level-regexp "\\)")) 17)
  629.              ;; ((looking-at "@subsubsection ") 17)
  630.              ;; ((looking-at "@unnumberedsubsubsec ") 17)
  631.              ;; ((looking-at "@appendixsubsubsec ") 17)
  632.              ;; ((looking-at "@subsubheading ") 17)
  633.              (t margin)))
  634.       (indent-to-column margin)
  635.       (beginning-of-line))))
  636.  
  637. ;;; The  tex  and  print  function definitions:
  638.  
  639. (defcustom texinfo-texi2dvi-command "texi2dvi"
  640.   "*Command used by `texinfo-tex-buffer' to run TeX and texindex on a buffer."
  641.   :type 'string
  642.   :group 'texinfo)
  643.  
  644. (defcustom texinfo-tex-command "tex"
  645.   "*Command used by `texinfo-tex-region' to run TeX on a region."
  646.   :type 'string
  647.   :group 'texinfo)
  648.  
  649. (defcustom texinfo-texindex-command "texindex"
  650.   "*Command used by `texinfo-texindex' to sort unsorted index files."
  651.   :type 'string
  652.   :group 'texinfo)
  653.  
  654. (defcustom texinfo-delete-from-print-queue-command "lprm"
  655.   "*Command string used to delete a job from the line printer queue.
  656. Command is used by \\[texinfo-delete-from-print-queue] based on
  657. number provided by a previous \\[tex-show-print-queue]
  658. command."
  659.   :type 'string
  660.   :group 'texinfo)
  661.  
  662. (defvar texinfo-tex-trailer "@bye"
  663.   "String appended after a region sent to TeX by `texinfo-tex-region'.")
  664.  
  665. (defun texinfo-tex-region (beg end)
  666.   "Run TeX on the current region.
  667. This works by writing a temporary file (`tex-zap-file') in the directory
  668. that is the value of `tex-directory', then running TeX on that file.
  669.  
  670. The first line of the buffer is copied to the
  671. temporary file; and if the buffer has a header, it is written to the
  672. temporary file before the region itself.  The buffer's header is all lines
  673. between the strings defined by `tex-start-of-header' and `tex-end-of-header'
  674. inclusive.  The header must start in the first 100 lines.
  675.  
  676. The value of `texinfo-tex-trailer' is appended to the temporary file after the region."
  677.   (interactive "r")
  678.   (require 'tex-mode)
  679.   (if (get-buffer "*tex-shell*")
  680.       (tex-kill-job)
  681.     (tex-start-shell))
  682.   (or tex-zap-file (setq tex-zap-file (make-temp-name "#tz")))
  683.   (let ((tex-out-file (concat tex-zap-file ".tex"))
  684.     (temp-buffer (get-buffer-create " tex-Output-Buffer"))
  685.     (zap-directory
  686.          (file-name-as-directory (expand-file-name tex-directory))))
  687.     (save-excursion
  688.       (save-restriction
  689.     (widen)
  690.     (goto-char (point-min))
  691.     (forward-line 100)
  692.     (let ((search-end (point))
  693.           (hbeg (point-min)) (hend (point-min))
  694.           (default-directory zap-directory))
  695.       (goto-char (point-min))
  696.           
  697.           ;; Copy first line, the `\input texinfo' line, to temp file
  698.       (write-region (point) 
  699.                         (save-excursion (end-of-line) (point))
  700.                         tex-out-file nil nil)
  701.           
  702.           ;; Don't copy first line twice if region includes it.
  703.           (forward-line 1)
  704.           (if (< beg (point)) (setq beg (point)))
  705.           
  706.           ;; Initialize the temp file with either the header or nothing
  707.           (if (search-forward tex-start-of-header search-end t)
  708.               (progn
  709.                 (beginning-of-line)
  710.                 (setq hbeg (point))    ; Mark beginning of header.
  711.                 (if (search-forward tex-end-of-header nil t)
  712.                     (progn (beginning-of-line)
  713.                            (setq hend (point)))    ; Mark end of header.
  714.                   (setq hbeg (point-min))))) ; Else no header.
  715.           
  716.           ;; Copy  header  to temp file.
  717.           (write-region (min hbeg beg) hend tex-out-file t nil)
  718.           
  719.           ;; Copy  region  to temp file.
  720.           (write-region (max beg hend) end tex-out-file t nil))
  721.         
  722.         ;; This is  a kludge to insert the tex-trailer into the tex-out-file.
  723.         ;;  We have to create a special buffer in which to insert
  724.         ;;  the tex-trailer first because there is no function with
  725.         ;;  which to append a literal string directly to a file.
  726.         (let ((local-tex-trailer texinfo-tex-trailer))
  727.           (set-buffer temp-buffer)
  728.           (erase-buffer)
  729.           ;; make sure trailer isn't hidden by a comment
  730.           (insert-string "\n")
  731.           (if local-tex-trailer (insert-string local-tex-trailer))
  732.           (tex-set-buffer-directory temp-buffer zap-directory)
  733.           (write-region (point-min) (point-max) tex-out-file t nil))
  734.  
  735. ;;; The following is sufficient in Emacs 19.
  736. ;;;    (write-region (concat "\n" texinfo-tex-trailer) nil
  737. ;;;              tex-out-file t nil)
  738.     ))
  739.     
  740.     (tex-set-buffer-directory "*tex-shell*" zap-directory)
  741.     (tex-send-command tex-shell-cd-command zap-directory)
  742.     (tex-send-command texinfo-tex-command tex-out-file))
  743.   (tex-recenter-output-buffer 0))
  744.  
  745. (defun texinfo-tex-buffer ()
  746.   "Run TeX on visited file, once or twice, to make a correct `.dvi' file."
  747.   (interactive)
  748.  
  749.   ;; Make sure TeX shell is running.
  750.   (require 'tex-mode)
  751.   (if (get-buffer "*tex-shell*")
  752.       (quit-process (get-process "tex-shell") t)
  753.     (tex-start-shell))
  754.  
  755.   (cond ((null buffer-file-name)
  756.          (error "Buffer not visiting any file!"))
  757.         ((buffer-modified-p)
  758.          (error "Buffer has been modified since last saved!")))
  759.  
  760.   (setq tex-zap-file buffer-file-name)
  761.  
  762.   (tex-send-command tex-shell-cd-command (file-name-directory tex-zap-file))
  763.  
  764.   (tex-send-command texinfo-texi2dvi-command tex-zap-file)
  765.  
  766.   (tex-recenter-output-buffer 0))
  767.  
  768. (defun texinfo-texindex ()
  769.   "Run `texindex' on unsorted index files.
  770. The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
  771. This runs the shell command defined by `texinfo-texindex-command'."
  772.   (interactive)
  773.   (require 'tex-mode)
  774.   (tex-send-command texinfo-texindex-command (concat tex-zap-file ".??"))
  775.   (tex-recenter-output-buffer nil))
  776.  
  777. (defun texinfo-tex-print ()
  778.   "Print `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
  779. This runs the shell command defined by `tex-dvi-print-command'."
  780.   (interactive)
  781.   (require 'tex-mode)
  782.   (tex-send-command tex-dvi-print-command (concat tex-zap-file ".dvi"))
  783.   (tex-recenter-output-buffer nil))
  784.  
  785. (defun texinfo-quit-job ()
  786.   "Quit currently running TeX job, by sending an `x' to it."
  787.   (interactive)
  788.   (if (not (get-process "tex-shell"))
  789.       (error "No TeX shell running"))
  790.   (tex-send-command "x"))
  791.  
  792. (defun texinfo-delete-from-print-queue (job-number)
  793.   "Delete job from the line printer spooling queue.
  794. You are prompted for the job number (use a number shown by a previous
  795. \\[texinfo-show-print-queue] command)."
  796.   (interactive "nPrinter job number for deletion: ")
  797.   (require 'tex-mode)
  798.   (if (tex-shell-running)
  799.       (tex-kill-job)
  800.     (tex-start-shell))
  801.   (tex-send-command texinfo-delete-from-print-queue-command job-number)
  802.   (tex-recenter-output-buffer nil))
  803.  
  804. (provide 'texinfo)
  805.  
  806. ;;; texinfo.el ends here
  807.